import { Button } from 'antd';
import {WeaDialog ,WeaNewScroll ,WeaLocaleProvider} from 'ecCom';
import {observer} from "mobx-react";
import _mapValues from 'lodash/mapValues'
import {WeaTableNew} from 'comsMobx';
const WeaTable = WeaTableNew.WeaTable;
const getLabel = WeaLocaleProvider.getLabel;

@observer
class ProjectFieldLogDialog extends React.Component {
    constructor(props) {
        super(props);
    }

    shouldComponentUpdate(nextProps,nextState){
        return true;
    }
 
    render() {
        const {title,tableStore,store} = this.props;
        const {fieldLogVisible} = store;
        return (
            <div>
            <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@1nr3a8`}
                title={title || getLabel(83,"日志")}
                visible={fieldLogVisible}
                buttons={this.getButtons()}
                icon="icon-coms-ModelingEngine"
                iconBgcolor="#217346"
                onCancel={()=>{store.setFieldLogVisible(false)}}
                style={{width:'700px', height:'400px'}}
            >
                    <WeaNewScroll ecId={`${this && this.props && this.props.ecId || ''}_WeaNewScroll@paj6pw`} height={"100%"}>
                        <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@sgp7wr`} 
                            comsWeaTableStore={tableStore}
                            hasOrder={true}
                            needScroll={false}
                            getColumns={c=>this.reRenderColumns(c)}
                        />
                    </WeaNewScroll>
            </WeaDialog>
        </div>)
    }
    getButtons(){
        const {store} = this.props;
        let btnArr = []; 
        btnArr.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@pp2tdv@close`}  type="primary" onClick={()=>store.setFieldLogVisible(false)}>{getLabel(309,"关闭")}</Button>)  
        return btnArr;
    }
   
    reRenderColumns(columns){
        const {store} = this.props;
        columns.forEach(c=>{
            if(c.dataIndex=='id'){
                c.render = function(text, record){
                    return <a href="javascript:void(0)" onClick={() => {
                        store.setField(record.fieldname);
                        store.setFieldName(record.fieldnamespan);
                        store.getPrjFieldDetaiLogList({prjid:store.prjid,fieldname:record.fieldname});
                        store.setFieldDetailLogVisible(true)}
                    }>{getLabel(82278,'查看该字段所有日志')}</a>;  
                }
            }
        })
        return columns;
    }
   
}

export default ProjectFieldLogDialog;